import axios from "axios";
// import { MessageBox } from "element-ui";

//axios 实例
const instance = axios.create({
    baseURL:'/api',
    timeout:8000,
    // headers:{'Bearer':localStorage.getItem("token")}
    
})

//请求拦截器
instance.interceptors.request.use((config) =>{
    const token = localStorage.getItem("token")
    if(token){
        config.headers.token = token
        config.headers["Authorization"] = `Bearer ${token}`
    }
    return config
})

//响应拦截器
// instance.interceptors.response.use((response) =>{
//     if(response.xxxxx == 401){
//         MessageBox.alert("登录已过期，请重新登录","错误",{
//             type:'error',
//             confirmButtonText:'去登录'
//         }).then(()=>{
//             localStorage.removeItem("xxxx")
//             window.location.reload()
//         })
//     }
//     return response
// })

export default instance

